package com.claims;

/**
 * Created by 峥桂 on 2017/6/6.
 */
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class CASTest {

    static int i=0;
    static AtomicInteger j=new AtomicInteger(0);
    public void  count(){
        i++;
    }
    public void safecount(){
        j.getAndIncrement();
    }
    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        final CASTest c = new CASTest();
        ExecutorService executorService = Executors.newFixedThreadPool(50);

        for(int k=0;k<100;k++)
        {
            executorService.execute(
                    new Runnable(){
                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            for(int m=0;m<100;m++)
                            {
                                c.count();
                                c.safecount();
                            }
                        }
                    }
            );

        }
        Thread.sleep(5000);
        System.out.println("castest 50 threads run add:");
        System.out.println("count:"+i);
        System.out.println("safecount:"+j.get());
    }
}